import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login.vue'

import home from '../components/home.vue'
import users from '../components/waters/users.vue'
import water from '../components/waters/water.vue'
import monitoring from '../components/waters/monitoring.vue'
import patrol from '../components/waters/patrol.vue'
import parameter from '../components/waters/parameter.vue'
import realtime from '../components/alarm/realtime.vue'
import historica from '../components/alarm/historica.vue'
import videostatistics from '../components/video/videostatistics.vue'
import server from '../components/video/server.vue'
import lookvideo from '../components/video/lookvideo.vue'
import tag from '../components/video/tag.vue'
import usermanagement from '../components/management/usermanagement.vue'
import logmanagement from '../components/management/logmanagement.vue'
import rightsmanagement from '../components/management/rightsmanagement.vue'
import report from '../components/report/report.vue'
import monitor from '../components/monitor/monitor.vue'
import drink from '../components/drink.vue'
import real from '../components/real.vue'
import history from '../components/history.vue'
Vue.use(VueRouter)

const routes = [
  {path: '/', redirect: '/login'},
  {path: '/Login', component: Login},
  {path: '/drink', component: drink},
  {path: '/home', component: home,
  redirect: '/monitor',
  children: [
    
    {path: '/monitor',component: monitor},
    {path: '/users',component: users},
    {path: '/water',component: water},
    {path: '/monitoring',component: monitoring},
    {path: '/patrol',component: patrol},
    {path: '/parameter',component: parameter},
    {path: '/realtime',component: realtime},
    {path: '/historica',component: historica},
    {path: '/videostatistics',component: videostatistics},
    {path: '/usermanagement',component: usermanagement},
    {path: '/logmanagement',component: logmanagement},
    {path: '/rightsmanagement',component: rightsmanagement},
    {path: '/report',component: report},
    {path: '/server',component: server},
    {path: '/lookvideo',component: lookvideo,
    children:[
    {path: '/real',component: real},
    {path: '/history',component: history},
   ]
  },
    {path: '/tag',component: tag},
    {path: '/real',component: real},
    
  ]
  }

]
const router = new VueRouter({
  routes
})
// router.beforeEach((to, from, next) => {
//   // 如果是访问login页面 直接放行 
//   // to表示将要去的路由地址对象
//   // from表示从何处来的路由地址对象
//   // next是一个方法
//   if (to.path == '/login') {
//     next()
//   } else {
//     // 如果访问不是从登录页面过来的,首先先验证token令牌,有token令牌 放行,没有就return 重新去登录
//     const token = sessionStorage.getItem('token')
     
//     // if (token) {
//     //   next()
//     // } else {
//     //   next('/login')
//     // }
//     if (!token) return next('/login')
//     next()
//   }
// })
export default router
